from page.net_project_page import NetProjectPage
from page.common_tools import CommonTools
from common.page import IOS, XPATH
import random as r
import time as t


today = t.strftime('%Y%m%d', t.localtime(t.time()))


class NetWorkPage(NetProjectPage, CommonTools):
    # 作业发布页面
    year_wheel = (XPATH, "//XCUIElementTypePickerWheel[1]")
    submit_work_btn = (IOS, "type == 'XCUIElementTypeStaticText' AND label == '提交作业'")
    qpl =(IOS,"type == 'XCUIElementTypeStaticText' AND label == '去评论'")
    not_view = (IOS, "type == 'XCUIElementTypeButton' AND label == '未批阅'")
    submint = (XPATH, "//XCUIElementTypeStaticText[contains(@name == '未提交')]")
    zijian = (IOS, 'type==XCUIElementTypeStaticText AND label="请输入自荐理由"')
    Xiangmu = (XPATH,"//XCUIElementTypeStaticText[contains(@name =='自动化测试作业')]")
    def release_work(self, title='%s自动化测试作业%d' % (today, r.randint(100, 999))):
        self.find_button("common release").click()
        self.find_element(XPATH,'//*[@name="请输入作业标题（40字内）"]').click()
        self.find_element(XPATH,'//*[@name="请输入作业标题（40字内）"]').send_keys(title)
        t.sleep(1)
        self.find_element(XPATH,'//*[@name="请输入作业要求（500字内）"]').click()
        self.find_element(XPATH,'//*[@name="请输入作业要求（500字内）"]').send_keys(
            "这是作业内容，你们先看看吧好不好会不会哈哈哈哈哈哈哈哈哈")
        self.hide_keyboard()
        self.find_button("下一步").click()
        self.find_static_text("发布范围").click()
        self.find_element(XPATH,'//*[@name="确定"]').click()
        self.find_static_text("语文计划").click()
        self.find_element(XPATH, '//*[@name="确定"]').click()
        self.find_static_text("开始时间").click()
        self.find_element(XPATH,'//*[@name="确定"]').click()
        self.find_static_text("截止时间").click()
        self.get_frame_center_and_swipe(self.year_wheel)
        self.find_element(XPATH,'//*[@name="确定"]').click()
        self.find_button(string="发布").click()
        t.sleep(3)
        self.swipe_dr('down')
        t.sleep(4)
        self.find_element(IOS, 'type == "XCUIElementTypeStaticText" AND label CONTAINS "%s"' % title).click()
        self.find_button(string="去批阅",contains_flag=1).click()
        self.swipe(320,160,320,160)    #提醒
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back light icon").click()



    def submit_work(self, title='自动化测试作业'):
        self.find_static_text(title, contains_flag=1).click()
        t.sleep(3)
        self.find_button(string="去评论",contains_flag=1).click()
        self.find_element(XPATH,"//XCUIElementTypeCell/XCUIElementTypeButton[2]").click()
        self.find_element(XPATH,"//XCUIElementTypeCell/XCUIElementTypeButton[3]").click()
        self.find_button(string="返回",contains_flag=1).click()
        self.find_button(string="提交作业",contains_flag=1).click()
        t.sleep(2)
        self.find_static_text(string="请输入正文内容",contains_flag=1).click()
        t.sleep(2)
        self.Edit_all()
        t.sleep(2)
        self.find_button("下一步").click()
        self.ZiJian()
        self.find_button("提交").click()
        t.sleep(3)
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        t.sleep(1)
        self.find_button(string="common back light icon", contains_flag=1).click()

    def submit_zizhu(self, title='自动化测试作业'):
        self.find_static_text(title, contains_flag=1).click()
        t.sleep(3)
        self.find_button(string="去评论",contains_flag=1).click()
        self.find_element(XPATH,"//XCUIElementTypeCell/XCUIElementTypeButton[2]").click()
        self.find_element(XPATH,"//XCUIElementTypeCell/XCUIElementTypeButton[3]").click()
        self.find_button(string="返回",contains_flag=1).click()
        self.find_button(string="提交作业",contains_flag=1).click()
        t.sleep(2)
        self.find_static_text(string="请输入正文内容",contains_flag=1).click()
        t.sleep(2)
        # self.find_static_text(string="请输入正文内容",contains_flag=1).click()
        self.Edit_all()
        # self.Fujian()  #附件
        t.sleep(2)
        self.find_button("下一步").click()
        self.ZiJian()
        self.find_button("提交").click()
        t.sleep(3)
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="common back dark icon", contains_flag=1).click()
        t.sleep(1)
        self.find_button(string="common back light icon", contains_flag=1).click()


    def view_work(self, title='自动化测试作业'):
        self.find_static_text(string="我的",contains_flag=1).click()   #我的
        self.find_static_text(title, contains_flag=1).click()
        t.sleep(3)
        # self.find_button(string="去批阅", contains_flag=1).click()
        # self.find_element(XPATH, '//*[@name="批阅状态"]').click()
        # self.find_static_text("未批阅").click()
        # # self.get_frame_center_and_click(self.not_view)
        # t.sleep(2)
        # self.swipe(320,160,320,160)   #去批阅
        # t.sleep(1)
        # self.find_element(XPATH,'//*[@name="批阅"]').click()   #批阅
        # self.find_static_text(string="优秀",contains_flag=1).click()
        # self.find_static_text(string="值得推荐",contains_flag=1).click()
        # self.find_static_text(string="请输入评语",contains_flag=1).click()
        # self.find_static_text(string="请输入评语",contains_flag=1).send_keys("自从你生下来的那一刹那起，你就注定要回去。这中间的曲折磨难、顺畅欢乐便是你的命运。不要因为命运的怪诞而俯首听命于它，任凭它的摆布。你一生的全部就在于：运你手里掌握的那一半就越庞大，你获得的就越丰硕。在你彻底绝望的时候，别忘了自己拥有一半的命运。这就是命运的一生；这就是一生的命运。")
        # # self.find_static_text("批阅").click()  # 点击其他位置以收回键盘
        # # self.find_button("确认").click()
        # self.find_button("完成").click()
        # self.find_button("查看详情").click()
        # t.sleep(2)
        # self.find_button(string="common back dark icon", contains_flag=1).click()
        # self.find_button(string="common back dark icon", contains_flag=1).click()
        # t.sleep(0.5)
        self.find_element(XPATH,'//*[@name="去查阅 >"]').click()  #去查阅
        self.PySelect()
        # self.find_element(XPATH,'//*[@name="优秀"]').click()     #去查阅
        self.swipe(320,160,320,160)  #去查阅
        t.sleep(3)
        self.find_button("common more dark icon").click()
        self.find_element(XPATH,'//*[@name="查阅"]').click()   #查阅
        self.swipe(50,550,50,550)
        self.find_element(XPATH,'//*[@name="请输入查阅内容"]').send_keys("查阅内容查阅内容")
        self.find_element(XPATH,'//*[@name="完成"]').click()
        self.find_button("查看详情").click()
        self.find_button("common back dark icon").click()
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_static_text("明细").click()
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back dark icon").click()
        t.sleep(0.5)
        self.find_button("common back light icon").click()
        t.sleep(2)

if __name__ == '__main__':
    test = NetWorkPage()
    # test.login('atgly')
    test.enter_project()
    test.enter_tools('作业')
    # test.release_work()
    # test.logout()
    # test.login('atxy1')
    # test.submit_work()
    test.view_work()
